// 将路由表解析成
import Layout from "@/layout/index.vue";
export const flterSyncRouter = (data) => {
  console.log(data);
  if (!Array.isArray(data)) return [];
  data.forEach((item) => {
    console.log(item);
    if (item.component === "Layout") {
      item.component = Layout;
    } else {
      item.component = loadView(item.component);
    }
    if (item.children && item.children.length) {
      flterSyncRouter(item.children); // 形成递归 把每一项都遍历出来
    }
    // console.log(data)
  });
  return data;
};
// 实现路由懒加载
const loadView = (views) => {
  return (resolve) => require([`@/views/${views}`], resolve);
};
// export const permission = {
//   inserted (el, binding, vnode) {
//     const { value } = binding // value
//     // console.log(value) // ['admin', 'user:add']
//     const roles = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user'))?.roles : []// 权限
//     // console.log(roles) // ['user:list', 'user:add', 'user:edit', 'monitor:list']
//     // console.log(JSON.parse(localStorage.getItem('user')).roles)
//     if (value && value instanceof Array && value.length > 0) {
//       const permissionRoles = value
//       const hasPermission = roles.some(role => {
//         return permissionRoles.includes(role)
//       })
//       console.log(Permissions)
//       // Permissions 为true 按钮存在
//       if (!hasPermission) {
//         el.parentNode && el.parentNode.removeChild(el)
//       }
//     } else {
//       throw new Error('need roles! Like v-permission="[\'admin\',\'editor\']"')
//     }
//   }
// }
